package service

import (
	__ "activity_srv/basic/proto"
	"activity_srv/handler/dao"
	"activity_srv/handler/models"
	"context"
	"fmt"
)

// 创建拼团商品
func (s *Serve) CreateGroupPGoods(_ context.Context, in *__.CreateGroupPGoodsReq) (*__.CreateGroupPGoodsResp, error) {
	var groupPGoods models.GroupPGoods
	err := dao.CreateGroupPGoods(in, groupPGoods)
	if err != nil {
		return nil, err
	}
	return &__.CreateGroupPGoodsResp{
		Message: "添加拼团商品成功",
	}, nil
}

// 拼团商品列表
func (s *Serve) GroupPGoodsList(_ context.Context, in *__.GroupPGoodsListReq) (*__.GroupPGoodsListResp, error) {
	list, err := dao.GroupPGoodsList(in)
	if err != nil {
		return nil, err
	}
	return &__.GroupPGoodsListResp{
		List: list,
	}, nil
}

// 拼团商品修改
func (s *Serve) GroupPGoodsUpdate(_ context.Context, in *__.GroupPGoodsUpdateReq) (*__.GroupPGoodsUpdateResp, error) {
	goods, err := dao.UpdateGroupPGoods(in)
	if err != nil {
		return nil, err
	}
	if err != nil {
		return nil, err
	}
	return &__.GroupPGoodsUpdateResp{
		Id: int64(goods),
	}, nil
}

// 拼团添加
func (s *Serve) GroupPGoodsDel(_ context.Context, in *__.GroupPGoodsDelReq) (*__.GroupPGoodsDelResp, error) {
	err := dao.DeleteGroupPGoods(in)
	if err != nil {
		return nil, err
	}
	fmt.Println(err)
	return &__.GroupPGoodsDelResp{
		Message: "删除拼图商品成功",
	}, nil
}
